package com.lbt.javaSE.digui;

import java.util.Scanner;

public class FBnaqie {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入N:");
        int n=sc.nextInt();
        while(n!=0){
//            int i = resultN(n);
            int i = youhua4(n);
            System.out.println("第"+n+"个数==_:"+i);
            System.out.println("请输入N(输入0结束):");
             n=sc.nextInt();
        }

    }

    public static int resultN(int n){
        if(n<=2) return 1;
        int[] array=new int[n+1];
        array[1]=array[2]=1;
        return resultN(n,array);
    }
    public static int resultN(int n,int[] array){
       if(array[n]==0){
           array[n]=resultN(n-1,array)+resultN(n-2,array);
       }
       return array[n];
    }
    public   static int youhua2(int n){
        if(n<=2) return 1;
        int[] array=new int[n+1];
        array[1]=array[2]=1;
        for(int i=3;i<=n;i++){
            array[i]=array[i-1]+array[i-2];
        }
        return array[n];
    }
    public   static int youhua3(int n){
        if(n<=2) return 1;
        int[] array=new int[2];
        array[1]=array[0]=1;
        for(int i=3;i<=n;i++){
            array[(i%2)]=array[(i-1)%2]+array[(i-2)%2];
        }
        return array[n%2];
    }
    public   static int youhua4(int n){
        if(n<=2) return 1;
        int[] array=new int[2];
        array[1]=array[0]=1;
        for(int i=3;i<=n;i++){
            array[(i&1)]=array[(i-1)&1]+array[(i-2)&1];
        }
        return array[n%2];
    }

}
